package com.topone.controller;

import org.dozer.DozerBeanMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public abstract class BaseController {

    protected final Logger LOG = LoggerFactory.getLogger(getClass());

    public static class BussinessAspect {
    }

    protected EntityManager entityManager;
    protected DozerBeanMapper daoDozerBeanMapper;

    @PersistenceContext
    protected void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    @Autowired
    protected void setDozerBeanMapper(DozerBeanMapper daoDozerBeanMapper) {
        this.daoDozerBeanMapper = daoDozerBeanMapper;
    }

    protected static boolean map(DozerBeanMapper daoDozerBeanMapper, Object source, Object dest) {
        if (daoDozerBeanMapper != null && source != null && dest != null) {
            daoDozerBeanMapper.map(source, dest);
            return true;
        }
        return false;
    }
}
